﻿using System;
using System.Linq;
using System.Runtime.Serialization;
using XcoAppSpaces.Security.None;

namespace XcoAppSpaces.Serialization.Binary
{
	class XcoClientCredentialsSerializationSurrogate : ISerializationSurrogate
	{
		public void GetObjectData(object obj, SerializationInfo info, StreamingContext context)
		{
			var msg = (XcoBasicClientCredentials)obj;
			info.AddValue("User", msg.User);
			info.AddValue("Password", msg.Password);
		}

		public object SetObjectData(object obj, SerializationInfo info, StreamingContext context, ISurrogateSelector selector)
		{
			obj = new XcoBasicClientCredentials(
				(string)info.GetValue("User", typeof(string)),
				(byte[])info.GetValue("Password", typeof(byte[])));
			return obj;
		}
	}
}